package com.hclc.entity.model;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.hclc.entity.model.series.CustomLocalDateTimeSerializer;
import com.hclc.entity.model.series.DeCustomLocalDateTimeSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p>任务执行记录表</p>
 * @author hef
 * @since 2020-11-09
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper=false)
@Accessors(chain = true)
@TableName("`t_job_execute_record`")
public class JobExecuteRecordModel implements Serializable {

	private static final long serialVersionUID = 1L;

    /**
     * id
     */
    @TableId(value="`id`", type= IdType.ASSIGN_ID)
	@ApiModelProperty(value = "id")
    private String id;

    /**
     * 任务执行时间
     */
    @TableField(value = "`log_datetime`")
	@ApiModelProperty(value = "任务执行时间")
    @JsonDeserialize(using = DeCustomLocalDateTimeSerializer.class)
    @JsonSerialize(using = CustomLocalDateTimeSerializer.class)
    private LocalDateTime logDatetime;

    @TableField("`job_exe_status`")
    @ApiModelProperty(value = "任务执行状态{success,1,成功;fail,2,失败;}")
    private JobExeStatusEnum jobExeStatus;
    public enum JobExeStatusEnum implements IEnum<Integer>{


        SUCCESS(1, "成功"),


        FAIL(2, "失败");



        @JsonValue
        @EnumValue
        private final int code;


        private final String desc;
        JobExeStatusEnum(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }
        @Override
        public Integer getValue() {
            return code;
        }
        public String getDesc(){return desc;}
        public static JobExeStatusEnum find( String desc ) throws IllegalArgumentException{
            for (JobExeStatusEnum model : JobExeStatusEnum.values()) {
                if (model.getDesc().equals(desc)) {
                    return model;
                }
            }
            throw new IllegalArgumentException();
        }
        @JsonCreator
        public static JobExeStatusEnum find( int code ) throws IllegalArgumentException{
            for (JobExeStatusEnum model : JobExeStatusEnum.values()) {
                if (model.getValue() == code) {
                    return model;
                }
            }
            throw new IllegalArgumentException();
        }
    }

    /**
     * 任务id
     */
    @TableField(value = "`job_id`")
	@ApiModelProperty(value = "任务id")
    private String jobId;

    /**
     * 更新时间
     */
    @TableField(value = "`update_time`", fill = FieldFill.INSERT_UPDATE)
	@ApiModelProperty(value = "更新时间")
    @JsonDeserialize(using = DeCustomLocalDateTimeSerializer.class)
    @JsonSerialize(using = CustomLocalDateTimeSerializer.class)
    private LocalDateTime updateTime;

    /**
     * 创建时间
     */
    @TableField(value = "`create_time`", fill = FieldFill.INSERT)
	@ApiModelProperty(value = "创建时间")
    @JsonDeserialize(using = DeCustomLocalDateTimeSerializer.class)
    @JsonSerialize(using = CustomLocalDateTimeSerializer.class)
    private LocalDateTime createTime;


}
